<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>检验报告详情</title>
	<%- include('../../../_global/baseLibs') %>
<link href="/quickJs/scripts/jquery/plug-ins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<script src="/quickJs/scripts/jquery/plug-ins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/quickJs/scripts/jquery/plug-ins/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
</head>

<body>
	<section class="page-wrap page-health">
		<!-- header start -->
		<header class="header-box grey fixed">
			<div class="header-content">
				<div class="left-tool">
					<a class="back" href="javascript:void(0);"><i
						class="iconfont icon-back"></i></a>
				</div>
				<div class="title">检验报告详情</div>
			</div>
		</header>
		<!-- header end -->

		<!--content start-->
			<aside class="report-basic-info">

				<div class="base-info">
					<h4 class="name hosName"></h4>
					<p class="time reportDate"></p>
				</div>
				<p class="p-text">
					<label class="label-text">检验项目：</label><label
						class="label1-text checkName"></label>
				</p>
				<p class="p-text">
					<label class="label-text">标本名称：</label><label
						class="label1-text specimenName"></label>
				</p>
				<p class="p-text">
					<label class="label-text">报告医生：</label><label
						class="label1-text docName"></label>
				</p>
				<p class="p-text">
					<label class="label-text">检验日期：</label><label
						class="label1-text checkDate"></label>
				</p>
			</aside>


			<aside class="report-result-box-jy">
				<table class="report-result-table">
					<tr>
						<th class="thh">项目</th>
						<th>结果</th>
						<th>参考值</th>
					</tr>
				</table>
			</aside>
			<!--content end-->
	</section>

</body>
<script type="text/javascript">
    function queryResult(result) {
        page_jybgxq.setBaseInfo(result.data[0]);
        page_jybgxq.setDetailInfo(result.data[0].checkInfos);
    }
    var page_jybgxq = (function($, page_jybgxq) {
        function queryJybgxq() {
            var params = {
                cardId : $.QuickUrlUtils.getRequest("cardId"),
                medicalOrgId : $.QuickUrlUtils.getRequest("medicalOrgId"),
                rid : $.QuickUrlUtils.getRequest("rid"),
                cardDate : $.QuickUrlUtils.getRequest("cardDate")
            };
            $.QuickRemote.AjaxJson({
                funcName: "/api/gzd/jyjc/queryJybgxq"
                ,params: params
                ,callback: page_jybgxq.queryReportResult
            });
        }

        /**  就诊页面跳转，查询实时接口，将结果转为健康档案标准结果  */
        function queryReportResult(result){
            if(result.length>0){
                result = result[0];
            }
            var data = {};
            data.hosName = $.QuickUrlUtils.getRequest("yymc");
            data.reportDate = $.QuickUrlUtils.getRequest("bgsj");
            data.docName = result.ysxm;
            data.checkName = result.jyxm;
            data.reportId = result.bgid;
            data.specimenName = result.bbmc;
            data.checkDate = result.jysj;
            page_jybgxq.setBaseInfo(data);

            var reportJybgDetailList = result.reportJybgDetailList;
            var checkInfos = [];
            for(var i in reportJybgDetailList){
                var reportJybgDetail = reportJybgDetailList[i];
                var checkInfo = {};
                checkInfo.referenceValue = reportJybgDetail.ckz;
                checkInfo.result = reportJybgDetail.xmjg;
                checkInfo.unit = reportJybgDetail.ckzdw;
                checkInfo.name = reportJybgDetail.xmmc;
                checkInfos.push(checkInfo);
            }
            page_jybgxq.setDetailInfo(checkInfos);
        }



        function setBaseInfo(info) {
            var baseContainer = $("aside.report-basic-info");
            for ( var key in info) {
                var value = info[key];
                var obj = baseContainer.find("." + key);
                obj.html(value);
            }
        }

        function setDetailInfo(info) {
            var detailContainer = $("aside.report-result-box-jy");
            var table = detailContainer.children("table");
            for ( var i in info) {
                var tr = page_jybgxq.initTr(info[i]);
                table.append(tr);
            }
        }

        function initTr(info) {
            var tr = $("<tr>");
            var name = $("<td>").html(info.name);
            var flag = page_jybgxq.compare(info.result, info.referenceValue);
            var result = page_jybgxq.mark(flag, info.result);
            var referenceValue = $("<td>").html(info.referenceValue + info.unit);
            tr.append(name).append(result).append(referenceValue);
            return tr;
        }

        function compare(value, referenceValue) {
            var range;
            if (!referenceValue)
                return "";
            if (referenceValue.indexOf("~") > -1) {
                range = referenceValue.split("~");
            } else if (referenceValue.indexOf("-") > -1) {
                range = referenceValue.split("-");
            }
            if (range && range.length == 2) {
                var min = range[0];
                var max = range[1];
                min = parseFloat(min);
                max = parseFloat(max);
                if (value < min)
                    return "down";
                else if (value > max)
                    return "up";
            } else {
                return "";
            }
        }
        function mark(mark, value) {
            var td = $("<td>");
            var i = $("<i>");
            var span = $("<span>").html(value).append(i);
            if (mark == "up") {
                i.addClass("icon-top");
                span.addClass("color-danger");
                td.append(span);
            } else if (mark == "down") {
                i.addClass("icon-down");
                span.addClass("color-info");
                td.append(span);
            } else {
                td.html(value);
            }
            return td;
        }

        var cfg_def = {
            queryJybgxq: queryJybgxq,
            queryReportResult: queryReportResult,

            setBaseInfo: setBaseInfo,
            setDetailInfo: setDetailInfo,
            initTr: initTr,
            compare: compare,
            mark: mark,
        }

        page_jybgxq.init = function(cfg){
            $.extend(page_jybgxq, cfg_def, cfg);
            page_jybgxq.queryJybgxq();

        }

        return page_jybgxq;
    })(jQuery, {});
    

</script>

</html>